package cc.bailongma.me;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class FindPwdActivity extends Activity implements View.OnClickListener{
	private EditText et_login_phone;
	private EditText et_login_yanzhengma;
	private TextView tv_get_yanzhengma;
	private TextView tv_count_down;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_find_pwd);
		setView();
	}

	private void setView() {
		et_login_phone=(EditText) findViewById(R.id.et_login_phone);
		et_login_yanzhengma=(EditText) findViewById(R.id.et_login_yanzhengma);
		tv_get_yanzhengma=(TextView) findViewById(R.id.tv_get_yanzhengma);
		tv_count_down=(TextView) findViewById(R.id.tv_count_down);
		tv_get_yanzhengma.setOnClickListener(this);
		findViewById(R.id.tv_next).setOnClickListener(this);
		findViewById(R.id.tv_back).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		Intent intent=new Intent();
		switch (v.getId()) {
		case R.id.tv_get_yanzhengma:
			tv_get_yanzhengma.setText("验证码已发送");
			new Thread(new Runnable() {
				@Override
				public void run() {
					for( int i=60;i>0;i--){
						try{
							Thread.sleep(1000);
							final String str="("+i+"s)";
							runOnUiThread(new  Runnable() {
								public void run() {
									tv_count_down.setText(str);
								}
							});
						}catch(Exception e){
							e.printStackTrace();
						}
					}
				}
			}).start();
			break;
		case R.id.tv_next:
			String yanzhengma=et_login_yanzhengma.getText().toString();
			String phone=et_login_phone.getText().toString();
			if(TextUtils.isEmpty(phone)){
				et_login_phone.setError("手机不能为空");return;
			}
			if(TextUtils.isEmpty(yanzhengma)){
				et_login_yanzhengma.setError("验证码不能为空");return;
			}
			if(yanzhengma.equals("ok")){
			intent.setClass(this, FindPwd2Activity.class);
			intent.putExtra("phone", phone);
			startActivity(intent);
			finish();
			}else{
				Toast.makeText(this, "错误", 0).show();
			}
			break;
		case R.id.tv_back:
			intent.setClass(this, LoginActivity.class);
			startActivity(intent);
			finish();
			break;
		}
		
	}
	
}
